package com.springstudy.advice;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author Tamako
 * @since 2025/1/10 11:50
 */
@Component
@Aspect
public class MyAdvice {
    @Pointcut("execution(void com.springstudy.service.impl.UserServiceImpl.show1())")
    public void myPointCut() {
    }

    @Before("execution(void com.springstudy.service.impl.UserServiceImpl.show1())")
    public void beforeAdvice(JoinPoint joinPoint) {
        System.out.println("beforeAdvice");
    }

    @After("execution(void com.springstudy.service.impl.UserServiceImpl.show1())")
    public void afterAdvice() {
        System.out.println("afterAdvice");
    }

    @Around("MyAdvice.myPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("beforeAdvice...");
        Object proceed = joinPoint.proceed();
        System.out.println("afterAdvice...");
        return proceed;
    }

    @AfterThrowing(pointcut = "execution(void com.springstudy.service.impl.UserServiceImpl.show1())", throwing = "e")
    public void afterThrowing(Throwable e) {
        System.out.println(e.getMessage());
        System.out.println("exception throwing");
    }
}
